#include "Player.h"
#include "Cards.h"
#include "Continents.h"


Player::Player(Cards* cards) : m_cards(cards), m_reinAvaible(0)
{
    static size_t number = 0;
    m_number = number;
    ++number;
    switch(m_number)
    {
        case 0:
            m_color = qRgb(205, 50, 0);
        break;
        case 1:
            m_color = qRgb(0, 180, 0);
        break;
        case 2:
            m_color = qRgb(0, 30, 200);
        break;
        case 3:
            m_color = qRgb(180, 180, 0);
        break;
        case 4:
            m_color = qRgb(0, 180, 180);
        break;
        case 5:
            m_color = qRgb(180, 180, 180);
        break;
        default:
            m_color = qRgb(0, 0, 0); // Shouldn't NEVER be used
        break;
    }
}

size_t Player::reinPerRound () const
{
    size_t n = 0;

    for(int i = 0; i < m_states.size(); ++i)
        if(m_cards->playerGotCard(m_states[i], this))
            ++n;


    return m_states.size()/3 + n + getContinents()->totalReinforcementBonus(m_states);
}

void Player::addState(State* state)
{
    if(m_states.indexOf(state) != -1)
        return;

    m_states.append(state);
}

bool Player::removeState(State* state)
{
    m_states.removeAll(state);

    if(isDefeated())
    {
        emit defeated();
        return true;
    }

    return false;
}

void Player::setReinforcement(size_t n)
{
    m_reinAvaible = n;
}

void Player::addReinforcement (size_t n)
{
    m_reinAvaible += n;
}

void Player::delReinforcement (size_t n)
{
    m_reinAvaible -= n;
}
